from django.db import models


# Create your models here.

class User_info(models.Model):
    user_name = models.CharField(verbose_name='账号', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=64)


class Article(models.Model):
    '''
    文章表
    '''
    category_choices = (
        (1, '咨询'),
        (2, '公司动态'),
        (3, '分享'),
        (4, '答疑'),
        (5, '其他'),
    )
    category = models.IntegerField(verbose_name='分类', choices=category_choices)
    title = models.CharField(verbose_name='标题', max_length=32)
    image = models.CharField(verbose_name='图片', max_length=128)
    summary = models.CharField(verbose_name='简介', max_length=255)

    comment_count = models.IntegerField(verbose_name='评论数', default=0)
    read_count = models.IntegerField(verbose_name='浏览数', default=0)

    author = models.ForeignKey(verbose_name='作者', to='User_info', on_delete=models.DO_NOTHING)
    date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)



class ArticleDetail(models.Model):
    article = models.OneToOneField(verbose_name='文章表', to='Article', on_delete=models.CASCADE)
    content = models.TextField(verbose_name='内容')


class Comment(models.Model):
    article = models.ForeignKey(verbose_name='文章id', to='Article', on_delete=models.DO_NOTHING)
    content = models.TextField(verbose_name='评论内容')
    user = models.ForeignKey(verbose_name='评论者', to='User_info', on_delete=models.DO_NOTHING)
    parent = models.ForeignKey(verbose_name='回复评论id', to='self', null=True, blank=True, on_delete=models.DO_NOTHING)
